const express = require('express')
const router = express.Router()

//  导出路由对象
module.exports = router;
const mysql = require('../db/mysql');
const {formatData} = require('../utils')

// 检测用户名是否被占用
// GET /api/user/check
router.get('/check',(req,res)=>{
    const {username} = req.query;
    let sql = `select id from user where username='${username}'`
    console.log('sql',sql)
    mysql.query(sql,(result)=>{
        if(result.length>0){
            res.send({
                code:400,
                msg:'user is exist',
                data:[]
            })
            // res.send(formatData())
        }else{
            res.send({
                code:200,
                msg:'ok',
                data:[]
            })
        }
    })
})



